package com.ifnk.portaljava.dapWeb.socket;

import com.ifnk.portaljava.dapWeb.common.MessageBean;
import com.ifnk.portaljava.dapWeb.common.Util;
import flex.messaging.MessageBroker;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class FlexUtil {
	private static Log loger = LogFactory.getLog(FlexUtil.class);
	
	public static void sendKeepAliveMessage(String message, boolean stopFlag, boolean erorFlag,
			String clientId) {
		MessageBean messageBean = new MessageBean();
		messageBean.setMessage(message);
		messageBean.setStopFlag(stopFlag);
		messageBean.setErrorFlag(erorFlag);
		loger.info("WebServer send KeepAlive MessagtoFlex clientId: " + clientId + " message: " + message);
		sendMessagtoFlex(messageBean, clientId);
	}

	public static void sendMessagtoFlex(Object message, String clientId) {
		MessageBroker messageBroker = MessageBroker.getMessageBroker(null);
		String subTopic = "KeepAlive" + clientId;
		Util.routeMessage(messageBroker, subTopic, clientId, message);
	}
	

}
